﻿using Common.Models;
using Common.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Wallpaper.Models.DTOs.Requests.Wallpaper;
using Wallpaper.Models.DTOs.Responses.message;
using Wallpaper.Services.IService;

namespace WallpaperApi.Controllers
{
    [Route("api/messages")]
    [ApiController]
    [Authorize]
    public class MessageController : BaseController
    {
        readonly IMessageService _messageService;

        public MessageController(IMessageService messageService)
        {
            _messageService = messageService;
        }

        /// <summary>
        /// 获取所有审核壁纸信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("review-wallpapers")]
        public async Task<ApiResponse<PagedResult<MessageResponse>>> GetReviewWallpapersMessages([FromQuery] PageRequest pageRequest)
        {
            var result = await _messageService.GetReviewWallpapersMessagesAsync(pageRequest);
            return ApiResponse<PagedResult<MessageResponse>>.Success(result);
        }


        /// <summary>
        /// 获取个人审核壁纸消息列表（分页）
        /// </summary>
        [HttpGet("user/review-wallpapers")]
        public async Task<ApiResponse<PagedResult<MessageResponse>>> GetUserReviewWallpapersMessages([FromQuery] PageRequest pageRequest)
        {
            var result = await _messageService.GetUserReviewWallpapersMessagesAsync(UserId, pageRequest);
            return ApiResponse<PagedResult<MessageResponse>>.Success(result);
        }

        /// <summary>
        /// 更新已读
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut("{id}/mark-read")] 
        public async Task<ApiResponse<Object>> MarkAsRead(string id)
        {
              await _messageService.MarkAsReadAsync(id);
            return ApiResponse<Object>.Success();
        }
    }
}
